<?php 

class Admin_UserController extends Zend_Controller_Action{
	protected $_userModel;

	public function init()
	{
		$this->_userModel = new Admin_Model_Users();
	}
	public function indexAction(){
		$request = $this->getRequest();
		$currentPage = 1;
		$resultsPerPage = 100;
		if($request->userId){
			$userId = $request->userId;
			$this->_userModel->addData(array("userId" => $userId));
		}else{
			if($request->page){
				$currentPage = $request->page;
			}
			
			$form = new Admin_Form_SearchUser(array(
				'action'	=>	'/admin/user/index',
				'method'	=>	'post'
			));
			
			if($this->getRequest()->isPost()){
				$data = $request->getPost();
				$this->_userModel->addData($data);
			}
			
			$this->view->form = $form;
		}	
		if($this->_userModel->getData()){
			
			$data = $this->_userModel->getData();
			if(isset($data->resultsPerPage))
				$resultsPerPage = $data->resultsPerPage;
			$result = Doctrine_Model_Users::adminGetUser($data);
			$paginator = Zend_Paginator::factory($result);
		    $paginator->setItemCountPerPage($resultsPerPage);
		    $paginator->setCurrentPageNumber($currentPage);
		    
		    $this->view->paginator=$paginator;
		}
	}
}